package myJs.user.workflow.featureSelection.preprocess

import com.softwaremill.quicklens._
import myJs.Implicits._
import AllCp.PreprocessT
import shared.pojo.WorkflowMission._
import myJs.myPkg.reactHookForm.UseFormRT
import myJs.tool.Tool
import myJs.tool.Tool._
import shared.Pojo.{ColRemoveSoftT, EachPreprocessData, FsPreprocessData}
import shared.pojo.WorkflowMission._

import japgolly.scalajs.react.vdom.all._
import japgolly.scalajs.react._
import japgolly.scalajs.react.React.Fragment
import japgolly.scalajs.react.util.EffectCatsEffect._
import myJs.myPkg.Hooks._
import cats.effect._
import myJs.Implicits._

/** Created by yz on 3/11/2020
  */
object ColRemoveCp extends PreprocessT with ColRemoveSoftT {

  case class Props(
      curI: Int,
      datasChange: List[EachPreprocessData] => SyncIO[Unit],
      datas: List[EachPreprocessData],
      insertModule: String => SyncIO[Unit],
      removeModule: Int => SyncIO[Unit]
  ) {
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  val Component = ScalaFnComponent[Props] { props =>
    object FTool {

      def colNaRateChange = (v: String) => {
        val newPreProcess = props.datas.modify(_.index(props.curI).colNaRate).setTo(v)
        props.datasChange(newPreProcess)
      }

      def removeModuleF = {
        props.removeModule(props.curI)
      }

      def insertModule = (moduleName: String) => {
        props.insertModule(moduleName)
      }

    }

    useEffect(
      SyncIO {
        Tool.popover
        ()
      },
      List()
    )

    val data = props.datas(props.curI)
    val namePrefix = s"preprocess.datas.${props.curI}"

    fieldset(
      paddingRight := "5px",
      border := "1px solid silver",
      margin := "0 2px",
      borderRadius := "4px",
      className := "northbtn myEachSoft",
      MyToolCp.Props(removeModule = FTool.removeModuleF, insertModule = FTool.insertModule).render,
      legend(s"${messages(nameStr)}"),
      div(
        InputGroupCp.Props(
          label = messages("threshold"),
          questionInfo = messages("thresholdInfo"),
          value = data.colNaRate,
          onChange = FTool.colNaRateChange,
          name = s"${namePrefix}.colNaRate"
        ).render
      )
    )

  }

  def cp(
      curI: Int,
      datas: List[EachPreprocessData],
      datasChange: List[EachPreprocessData] => SyncIO[Unit],
      insertModule: String => SyncIO[Unit],
      removeModule: Int => SyncIO[Unit],
      extraData: ExtraData
  ) = {
    ColRemoveCp.Props(
      curI = curI,
      datas = datas,
      datasChange = datasChange,
      insertModule = insertModule,
      removeModule = removeModule
    ).render
  }

}
